{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Norm\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### I. Lý thuyết"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Xem kỹ thêm tại [Norm (mathematics) - Wiki](https://en.wikipedia.org/wiki/Norm_(mathematics))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Norm của một vector là chiều dài của vector đó"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### II. L2 Norm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "L2 Norm là căn tổng bình phương các giá trị của vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 1. Công thức"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://lh3.googleusercontent.com/GxVNkKW67UltrjU1HBiEQqEO9qJcPbLa3kiRQCLYRMkOcb0Ak2ok_wG5dAikwvY6Q3TTLzA-OEZNopn9OQzYzT6F91cqSQm6KIRwOY9CxdanNsJDKhWg3J6mq0NFSmg-YcPH6h3OKIhGpOMqt_Lb0DAnthCsXNMO5QgzQPBp9FT56Nsm295e5lk7a397agWuWHEhOZnHOImGgrDYVPjeShQDIR4fFDw-WkpAfo2uhEQetxcBY8gEnr8GTeuUq4lic0_ZVO4ajB59WCO7DMK3bdf1Fhc5ll_GnIrRkYY7IqhQ1-ixzrjcAy7j7YpoF14K8IAhr3q05AYvKdi0Z9IBRoaqhis-Bpo-F__TxYzh_7SpKXdUhYG3HZVKtt-mJPd8bSbNuLOvbiF-FIJ-NhlRPblUpDbxgvldk1hognaVoJE4mYK2HrOLyaDhO2BwCKBbrJgTq9GRaMmuvuUEw4kSitbK3oHwMZRRlUteojH3wIyKyM58gRMeNXniSOPsMKBXiKztGDOUg-cvEdt4dgEFMD7AxkKYWWNQUmduKAHXTdpZeo1M4Fk3UkKSKh9CKOBodBNxlC3WJKKxOHjy0pPc7dymKXs1LPHfKo9gZ_k8PaVUw0gMGtTpkMBfnlFontXscL9rasMOqYijpJUceZEw9-snYYL6nEKc11ycIsIyE4KrkeQH08eZXjB4qQ=w224-h43-no)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 2. Thực hành với Numpy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Xem kỹ thêm tại [numpy.linalg.norm](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.norm.html#r46)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import linalg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([1, 2, 3, 2, 3, 4])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Norm L2 of A = $\\sqrt{1^2 + 2^2 + 3^2 + 2^2 + 3^2 + 4^2}$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.557438524302"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linalg.norm(A)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### II. L1 Norm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "L1 Norm là tổng trị tuyệt đối các giá trị của vector"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 1. Công thức"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://lh3.googleusercontent.com/uzCainyremkiwITH4K73qHz0gKXvyxgwEFIc9Q_7nP4fVC6ncYc8vekrdDKGjMDyRZ96I6HVX7ygutv8opJdL0Tn5Dzzwm3bK1zzpBjQ8l9SUfhOwAAj_iOXyJl_x57jXbAyZDgwWpQym9BYE5OT2OVL_8WC7WpL05XJtXhu2H2Wca-_S45khXtJEuzEv0HdqZDtR7paX3ea2OTh7wWMl9RpbUlwbOWEqq_4_usn4zvpvsFx9JSnV6D_ggt4kVBxeceFBUIyG7XY3An7iDAFD2qAHn94hYzr8x5hr-_KnKvqeFVQqVmkkOmWitfRkOan33vHgVhyjpZFlIL3dD0xwCHbcSR6YwPXQiieGPiUO6K-A3-fnJ0SrbUvTxUNM7byQA4Ux8rlnXm92dy_R232ttyj-LSPWXw4OslR9fUedl8qRUxqQs2f3oO520o5E_OKqh7mMyziy4ShkpJTz8uk_-dxtvIVNo0Enwby0z3FO7REU_OYzpoeySmxb-tlBexgWcQLSoMt0-tnzdHhsqDGDSvWubU_lRBnSeveZTrid3IwSR2wxjxahd7bE6VJp1SehkLj048ShW2OJ7F-rWltIjfzkeoUen7s5PZ1KRdOI97AO_CbZItcW6ScNG7qFfUFDzuL0HQ_-qEuLY4Sg-ImJ1QasB4pwXLPwOoKI68B7mhKKZECC1SrB1z9Yw=w178-h60-no)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 2. Thực hành với Numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "B = np.array([6, 20, 10, -4])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Norm L1 of B = |6|  + |20| + |10| + |-4|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "40.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linalg.norm(B, ord=1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
